package Thread.callable;

/**
 * 使用Runnable实现
 */
public class NoCallable {
    private static class Count{
        int sum=0;
        Object lock=new Object();
    }

    public static void main(String[] args) throws Exception {
        Count count=new Count();
        Thread t=new Thread(()->{
           int sum=0;
            for (int i = 0; i <=1000 ; i++) {
                sum+=i;
            }
            synchronized (count.lock) {
                count.sum = sum;
                //唤醒主线程
                count.lock.notify();
            }
        });
        t.start();
        //主线程阻塞等待子线程执行完毕之后再打印结果
        synchronized (count.lock){
            if (count.sum==0){
                count.lock.wait();
            }
        }
        System.out.println("子线程执行结束，最终结果为："+count.sum);
        }
    }

